<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>robot Tree Mouse Test</title>

	<style>
		@import "../../../../util/doh/robot/robot.css";
	</style>

	<script type="text/javascript" src="../../../../dojo/dojo.js"></script>

	<script type="text/javascript">
		require([
			"doh/runner", "dojo/robotx",
			"dojo/query",
			"dijit/tests/helpers", "dojo/domReady!"
		], function(doh, robot, query, helpers){

			robot.initRobot('../test_Tree.html');

			var registry, mytree, africa;

			doh.register("_setup", [
				{
					name: "wait for widgets to load",
					timeout: 20000,
					runTest: helpers.waitForLoad
				},
				function setVars(){
					registry = robot.window.require("dijit/registry");
					mytree = registry.byId("mytree");

					// find TreeNode for Africa
					var node = query(".dijitTreeLabel")[1];
					africa = registry.getEnclosingWidget(node);
				}
			]);

			function toggle(func, expanded){
				return function(){
					var d = new doh.Deferred();

					doh.is(expanded, africa.isExpanded, "original state");

					func();

					robot.sequence(d.getTestCallback(function(){
						doh.is(!expanded, africa.isExpanded, "after state");
					}), 500);

					return d;
				};
			}

			doh.register("label click", [
				{
					name: "click to open",
					timeout: 8000,
					runTest: toggle(function(){
						robot.mouseMoveAt(africa.labelNode);
						robot.mouseClick({left:true}, 100);
					}, false)
				},

				{
					name: "click to close",
					timeout: 8000,
					runTest: toggle(function(){
						robot.mouseClick({left:true}, 100);
					}, true)
				},

				{
					name: "double click to open",
					timeout: 8000,
					setUp: function(){
						mytree.openOnClick = false;
						mytree.openOnDblClick = true;
					},
					runTest: toggle(function(){
						robot.mouseClick({left:true}, 100);
						robot.mouseClick({left:true}, 100);
					}, false)
				},

				{
					name: "double click to close",
					timeout: 8000,
					runTest: toggle(function(){
						robot.mouseClick({left:true}, 100);
						robot.mouseClick({left:true}, 100);
					}, true)
				}
			]);

			doh.run();
		});

	</script>
</head>
</html>

